package com.sinsoft.monitorDemo.dao;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;
import java.util.ResourceBundle;

import com.sinsoft.monitorDemo.entity.Threshold;

public class ThresholdDao {
	//得到所有的阈值
	public Threshold getAllThreshold(){
		
		Threshold threshold;
		ResourceBundle bundle = ResourceBundle.getBundle("threshold");	
		threshold = new Threshold(Integer.parseInt(bundle.getString("cpuUsed")), Integer.parseInt(bundle.getString("cpuIowait")), 
				Integer.parseInt(bundle.getString("memUsed")), Integer.parseInt(bundle.getString("swapUsed")), 
				Integer.parseInt(bundle.getString("diskUsed")), bundle.getString("portStatus"), bundle.getString("service"), 
				Integer.parseInt(bundle.getString("tomcatCpuUsed")), Integer.parseInt(bundle.getString("tomcatMemUsed")), 
				Integer.parseInt(bundle.getString("nginxCpuUsed")), Integer.parseInt(bundle.getString("nginxMemUsed")), 
				Integer.parseInt(bundle.getString("mysqlCpuUsed")), Integer.parseInt(bundle.getString("mysqlMemUsed")), 
				Integer.parseInt(bundle.getString("oracleTmpfsUsed")), bundle.getString("oracleCrs"), 
				bundle.getString("oracleAsm"), bundle.getString("oracleDiskGrop"), bundle.getString("oracleListen"), 
				bundle.getString("oracleNetVip"), bundle.getString("oracleInstance"), bundle.getString("oracleDataBase"), 
				Integer.parseInt(bundle.getString("oracletablespaceused")));
		return threshold;	
	}
	
	//更新阈值
	public void changeThreshold(String key,String value){
		Properties prop = new Properties();
		String path = ThresholdDao.class.getResource("/").getPath();
		try {
			InputStream in = new FileInputStream(path+"threshold.properties");
			prop.load(in);
			OutputStream fos = new FileOutputStream(path+"threshold.properties");  
			prop.setProperty(key, value);
			prop.store(fos, "Update value");
			fos.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
